<?php

header("Content-type:text/html;charset=utf-8");

	require_once('../config.php');

	$date = time();

	$title=$_POST['title'];

	$description=$_POST['description'];

	$content=$_POST['content'];

    $file = $_FILES['file'];//得到传输的数据
	//得到文件名称
	$name = $file['name'];


	print_r($_POST);exit;

	$type = strtolower(substr($name,strrpos($name,'.')+1)); //得到文件类型，并且都转化成小写
	$allow_type = array('jpg','jpeg','gif','png'); //定义允许上传的类型
	//判断文件类型是否被允许上传
	if(!in_array($type, $allow_type)){
	  //如果不被允许，则直接停止程序运行
	  return ;
	}
	//判断是否是通过HTTP POST上传的
	if(!is_uploaded_file($file['tmp_name'])){
	  //如果不是通过HTTP POST上传的
	  return ;
	}
	$upload_path ="./upload/"; //上传文件的存放路径
	//开始移动文件到相应的文件夹
	if(move_uploaded_file($file['tmp_name'],$upload_path.$file['name'])){

		$sql = 'INSERT INTO picture (url,updateTime,is_open,description,title,content) VALUES ("'.$file['name'].'","'.$date.'",1,"'.$description.'","'.$title.'","'.$content.'")';

		if($con->query($sql)){

			header('location:http://localhost/hkong/hk-admin/index.php');
			// header('location: '.$_SERVER['HTTP_REFERER']);
		}else{

			echo "插入图片失败";
		}  
	}else{
		// var_dump($upload_path);
	  echo "Failed!";
	}

?>